<?php
class ControllerExtensionModuleMobileIcon extends Controller {
	public function index($setting) {
		if (!$this->config->get('is_mobile')) return;

		if (empty($setting['image'])) return;

		$this->load->model('tool/image');
		$data['placeholder'] = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);

		$images = $setting['image'];
		$sort_order = array();
		foreach ($images as $key => $value) {
			$sort_order[$key] = $value['sort_order'];
		}
		array_multisort($sort_order, SORT_ASC, $images);

		$data['images'] = array();
		foreach ($images as $image) {
			$image_info = array();

			if (isset($image['title']) && !empty($image['title'])) {
				$image_info['title'] = trim($image['title']);
			} else {
				$image_info['title'] = '---';
			}

			if (isset($image['link']) && !empty($image['link'])) {
				$image_info['link'] = trim($image['link']);
			} else {
				$image_info['link'] = '#';
			}

			if (isset($image['image']) && is_file(DIR_IMAGE . $image['image'])) {
				$image_info['image'] = $this->model_tool_image->resize($image['image'], $setting['width'], $setting['height']);
			} else {
				$image_info['image'] = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
			}

			$data['images'][] = $image_info;
		}

		if ($data['images']) {
			return $this->load->view('extension/module/mobile_icon.tpl', $data);
		}
	}
}
